package jsyf.oa.dao.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

import jsyf.oa.entity.system.RoleRightConfigLogEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;

@Repository
public class RoleRightConfigLogDao extends BaseDao {

    public RoleRightConfigLogDao() {
        super.iBaseEntity = new RoleRightConfigLogEntity();
    }

    public List<RoleRightConfigLogEntity> getEntityListByCondition(String condition, Object[] params) {
        List<JSONObject> jsonList = getJSONListByCondition(condition, params);
        List<RoleRightConfigLogEntity> entityList = new ArrayList<>();
        for (int i = 0; i < jsonList.size(); i++) {
            RoleRightConfigLogEntity entity = (RoleRightConfigLogEntity) convertJson2Entity(jsonList.get(i));
            entityList.add(entity);
        }
        return entityList;
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, RoleRightConfigLogEntity.class);
    }



    @Override
    public List<JSONObject> getJSONListByPage(String condition, Object[] params, int requestPage, int pageSize) {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT\n" +
                "\tt1.ID AS id ,\n" +
                "\tt3. NAME AS createUserName ,\n" +
                "\tt2. NAME AS roleName ,\n" +
                "\tt1.CREATE_USER_ID AS createUserId ,\n" +
                "\tt1.CREATE_TIME AS createTime ,\n" +
                "\tt1.CHANGE_BEFORE_IDS AS changeBeforeIds ,\n" +
                "\tt1.CHANGE_AFTER_IDS AS changeAfterIds ,\n" +
                "\tt1.CHANGE_TYPE AS changeType ,\n" +
                "\tt1.REMARK AS remark ,\n" +
                "\tt1.ROLE_NAME_ID AS roleNameId ,\n" +
                "\tt1.CHANGE_BEFORE_NAMES AS changeBeforeNames ,\n" +
                "\tt1.CHANGE_AFTER_NAMES AS changeAfterNames\n" +
                "FROM\n" +
                "\tt_sys_role_right_config_log AS t1 ,\n" +
                "\tt_sys_role_name AS t2 ,\n" +
                "\tt_sys_user AS t3\n" +
                "WHERE\n" +
                "\tt1.CREATE_USER_ID = t3.ID\n" +
                "AND t1.ROLE_NAME_ID = t2.ID\n" +
                "ORDER BY\n" +
                "\tt1.CREATE_TIME DESC");
        sql.append(condition);
        super.appendPageSql(sql, requestPage, pageSize);

        List<JSONObject> jsonList = super.queryForJsonList(sql.toString(), params);

        return jsonList;
    }
}

